<!DOCTYPE html>
<html lang="en">
  <head>
    <title>
        Java-xml-WebService - rulerLwx Blog
      </title>
        <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-transform" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,adress=no">
    
    <meta name="theme-color" content="#000000" />
    
    <meta http-equiv="window-target" content="_top" />
    
    
    <meta name="description" content="SOAP &amp;amp; WSDL SOAP是一种交换数据的协议规范，用于规范服务端和客户端之间数据传输的规则。 SOAP是基于HTTP协议进行传输，说白点，用SOAP协议" />
    <meta name="generator" content="Hugo 0.73.0 with theme pure" />
    <title>Java-xml-WebService - rulerLwx Blog</title>
    
    
    <link rel="stylesheet" href="https://rulerLwx.gitee.io/css/style.min.c4bc7071f132c964c2116bca53b392933f377e5ca7b7051ed245187c621a2d3e.css">
    
    <link rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/9.15.10/styles/github.min.css" async>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.css" async>
    <meta property="og:title" content="Java-xml-WebService" />
<meta property="og:description" content="SOAP &amp; WSDL SOAP是一种交换数据的协议规范，用于规范服务端和客户端之间数据传输的规则。 SOAP是基于HTTP协议进行传输，说白点，用SOAP协议" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://rulerLwx.gitee.io/2019/08/java-xml-webservice/" />
<meta property="article:published_time" content="2019-08-03T11:02:30+08:00" />
<meta property="article:modified_time" content="2019-08-03T11:02:30+08:00" />
<meta itemprop="name" content="Java-xml-WebService">
<meta itemprop="description" content="SOAP &amp; WSDL SOAP是一种交换数据的协议规范，用于规范服务端和客户端之间数据传输的规则。 SOAP是基于HTTP协议进行传输，说白点，用SOAP协议">
<meta itemprop="datePublished" content="2019-08-03T11:02:30&#43;08:00" />
<meta itemprop="dateModified" content="2019-08-03T11:02:30&#43;08:00" />
<meta itemprop="wordCount" content="2465">



<meta itemprop="keywords" content="" /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Java-xml-WebService"/>
<meta name="twitter:description" content="SOAP &amp; WSDL SOAP是一种交换数据的协议规范，用于规范服务端和客户端之间数据传输的规则。 SOAP是基于HTTP协议进行传输，说白点，用SOAP协议"/>

    <!--[if lte IE 9]>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
      <![endif]-->

    <!--[if lt IE 9]>
        <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
      <![endif]-->
  </head>

  
  

  <body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage"><header class="header" itemscope itemtype="http://schema.org/WPHeader">
    <div class="slimContent">
      <div class="navbar-header">
        <div class="profile-block text-center">
          <a id="avatar" href="https://gitee.com/rulerLwx" target="_blank">
            <img class="img-circle img-rotate" src="https://rulerLwx.gitee.io/avatar.png" width="200" height="200">
          </a>
          <h2 id="name" class="hidden-xs hidden-sm">rulerLwx</h2>
          <h3 id="title" class="hidden-xs hidden-sm hidden-md">thinking...</h3>
          <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i>Guangzhou, China</small>
        </div><div class="search" id="search-form-wrap">
    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="Search" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i
                        class="icon icon-search"></i></button>
            </span>
        </div>
        <div class="ins-search">
            <div class="ins-search-mask"></div>
            <div class="ins-search-container">
                <div class="ins-input-wrapper">
                    <input type="text" class="ins-search-input" placeholder="Type something..."
                        x-webkit-speech />
                    <button type="button" class="close ins-close ins-selectable" data-dismiss="modal"
                        aria-label="Close"><span aria-hidden="true">×</span></button>
                </div>
                <div class="ins-section-wrapper">
                    <div class="ins-section-container"></div>
                </div>
            </div>
        </div>
    </form>
</div>
        <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
      </div>
      <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
        <ul class="nav navbar-nav main-nav">
            <li class="menu-item menu-item-home">
                <a href="/">
                    <i class="icon icon-home-fill"></i>
                  <span class="menu-title">Home</span>
                </a>
            </li>
            <li class="menu-item menu-item-archives">
                <a href="/posts/">
                    <i class="icon icon-archives-fill"></i>
                  <span class="menu-title">Archives</span>
                </a>
            </li>
            <li class="menu-item menu-item-categories">
                <a href="/categories/">
                    <i class="icon icon-folder"></i>
                  <span class="menu-title">Categories</span>
                </a>
            </li>
            <li class="menu-item menu-item-tags">
                <a href="/tags/">
                    <i class="icon icon-tags"></i>
                  <span class="menu-title">Tags</span>
                </a>
            </li>
            <li class="menu-item menu-item-about">
                <a href="/about/">
                    <i class="icon icon-cup-fill"></i>
                  <span class="menu-title">About</span>
                </a>
            </li>
        </ul>
      </nav>
    </div>
  </header>

<aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">Board</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">enjoy~
            </div>
        </div>
    </div>
</div>

      <div class="widget">
    <h3 class="widget-title"> Categories</h3>
    <div class="widget-body">
        <ul class="category-list">
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/java-framework/" class="category-list-link">java-framework</a><span class="category-list-count">38</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/java-front-end/" class="category-list-link">java-front-end</a><span class="category-list-count">11</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/java-se/" class="category-list-link">java-se</a><span class="category-list-count">21</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/java-senior/" class="category-list-link">java-senior</a><span class="category-list-count">4</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/linux/" class="category-list-link">linux</a><span class="category-list-count">13</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/tools/" class="category-list-link">tools</a><span class="category-list-count">1</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/%E6%8A%80%E6%9C%AF%E6%9D%82%E7%83%A9/" class="category-list-link">技术杂烩</a><span class="category-list-count">4</span></li>
            <li class="category-list-item"><a href="https://rulerLwx.gitee.io/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/" class="category-list-link">数据库</a><span class="category-list-count">15</span></li>
        </ul>
    </div>
</div>
      <div class="widget">
    <h3 class="widget-title"> Tags</h3>
    <div class="widget-body">
        <ul class="tag-list">
            
            
            <li class="tag-list-item"><a href="https://rulerLwx.gitee.io/tags/jvm/" class="tag-list-link">jvm</a><span
                    class="tag-list-count">1</span></li>
            
            
            <li class="tag-list-item"><a href="https://rulerLwx.gitee.io/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" class="tag-list-link">多线程</a><span
                    class="tag-list-count">2</span></li>
            
            
            <li class="tag-list-item"><a href="https://rulerLwx.gitee.io/tags/%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B/" class="tag-list-link">网络编程</a><span
                    class="tag-list-count">3</span></li>
            
        </ul>

    </div>
</div>
      
<div class="widget">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget-body">
        <ul class="recent-post-list list-unstyled no-thumbnail">
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/%E8%87%AA%E5%B7%B1%E5%8A%A8%E6%89%8B%E4%B8%80%E6%89%B9%E9%87%8F%E7%A7%BB%E5%8A%A8%E9%87%8D%E5%91%BD%E5%90%8D%E6%96%87%E4%BB%B6/" class="title">自己动手（一）——批量移动、重命名文件</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-27 17:50:02 &#43;0800 CST" itemprop="datePublished">2020-07-27</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/%E5%85%B3%E4%BA%8Einteger%E7%9A%84-128~127%E7%BC%93%E5%AD%98/" class="title">关于Integer的 -128~127缓存</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-11 16:56:21 &#43;0800 CST" itemprop="datePublished">2020-07-11</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98/" class="title">跨域问题</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-08 22:41:12 &#43;0800 CST" itemprop="datePublished">2020-07-08</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/%E4%B8%AA%E4%BA%BA%E5%8D%9A%E5%AE%A2%E6%90%AD%E5%BB%BA/" class="title">个人博客搭建</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-05 18:58:47 &#43;0800 CST" itemprop="datePublished">2020-07-05</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://rulerLwx.gitee.io/2020/07/mongodb-1/" class="title">MonggoDB-1</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-03 18:58:47 &#43;0800 CST" itemprop="datePublished">2020-07-03</time>
                    </p>
                </div>
            </li>
        </ul>
    </div>
</div>
  </div>
</aside>

    
    
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <h4 class="toc-title">Catalogue</h4>
    <nav id="toc" class="js-toc toc">

    </nav>
  </div>
</aside>
<main class="main" role="main"><div class="content">
  <article id="-" class="article article-type-" itemscope
    itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      <h1 itemprop="name">
  <a
    class="article-title"
    href="/2019/08/java-xml-webservice/"
    >Java-xml-WebService</a
  >
</h1>

      <div class="article-meta">
        
<span class="article-date">
  <i class="icon icon-calendar-check"></i>&nbsp;
<a href="https://rulerLwx.gitee.io/2019/08/java-xml-webservice/" class="article-date">
  <time datetime="2019-08-03 11:02:30 &#43;0800 CST" itemprop="datePublished">2019-08-03</time>
</a>
</span>
<span class="article-category">
  <i class="icon icon-folder"></i>&nbsp;
  <a class="article-category-link" href="/categories/java-framework/"> Java-framework </a>
</span>

        <span class="post-comment"><i class="icon icon-comment"></i>&nbsp;<a href="/2019/08/java-xml-webservice/#comments"
            class="article-comment-link">Comments</a></span>
		<span class="post-wordcount hidden-xs" itemprop="wordCount">Word Count: 2465words</span>
		<span class="post-readcount hidden-xs" itemprop="timeRequired">Read Count: 5minutes </span>
      </div>
    </div>
    <div class="article-entry marked-body js-toc-content" itemprop="articleBody">
      <h1 id="soap--wsdl">SOAP &amp; WSDL</h1>
<ul>
<li>SOAP是一种交换数据的协议规范，用于规范服务端和客户端之间数据传输的规则。</li>
<li>SOAP是基于HTTP协议进行传输，说白点，<strong>用SOAP协议写好的xml信息放在HTTP协议的请求体中</strong>发送到服务器或客户諯。</li>
</ul>
<pre><code class="language-xml">    请求：

    POST /stockquote.asmx HTTP/1.1
    Host: www.webservicex.net
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: &quot;http://www.webserviceX.NET/GetQuote&quot;

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
    &lt;soap:Envelope xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
      &lt;soap:Body&gt;
        &lt;GetQuote xmlns=&quot;http://www.webserviceX.NET/&quot;&gt;
          &lt;symbol&gt;string&lt;/symbol&gt;
        &lt;/GetQuote&gt;
      &lt;/soap:Body&gt;
    &lt;/soap:Envelope&gt;
</code></pre>
<pre><code class="language-xml">    响应：

    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
    &lt;soap:Envelope xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:soap=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot;&gt;
      &lt;soap:Body&gt;
        &lt;GetQuoteResponse xmlns=&quot;http://www.webserviceX.NET/&quot;&gt;
          &lt;GetQuoteResult&gt;string&lt;/GetQuoteResult&gt;
        &lt;/GetQuoteResponse&gt;
      &lt;/soap:Body&gt;
    &lt;/soap:Envelope&gt;

</code></pre>
<ul>
<li>WSDL，跟SOAP一点关系也没有，它只是一个描述服务的xml文件，它只有两个作用：一是让开发人员看，二是让第三方框架生成代码或动态调用。</li>
</ul>
<h1 id="调用ws">调用WS</h1>
<p>客户端调用WS的方式有哪几种：</p>
<ol>
<li>客户端硬编程方式</li>
<li>ajax调用js+xml方式</li>
<li>url connection方式</li>
<li>生成客户端代码方式（wsimport/wsdl2java等)，如使用axis2、cxf等框架。</li>
</ol>
<h2 id="客户硬端编程方式">客户硬端编程方式</h2>
<p>需要三个元素：</p>
<p>1.javax.xml.ws.Service类
2.javax.xml.namespace.QName类
3.用wsimport生成的一个service接口。</p>
<pre><code class="language-java">public class App {

    public static void main(String[] args) throws Exception {
        URL wsdlUrl = new URL(&quot;http://192.168.1.100:6789/hello?wsdl&quot;);
        Service s = Service.create(wsdlUrl, new QName(&quot;http://ws.itcast.cn/&quot;,&quot;HelloServiceService&quot;));
        HelloService hs = s.getPort(new QName(&quot;http://ws.itcast.cn/&quot;,&quot;HelloServicePort&quot;), HelloService.class);
        String ret = hs.sayHello(&quot;zhangsan&quot;);
        System.out.println(ret);
    }
}
</code></pre>
<p>其中 HelloService 是用 wsimport 生成的一个接口。</p>
<h2 id="ajax方式">Ajax方式</h2>
<pre><code class="language-html">&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
    &lt;meta charset=&quot;UTF-8&quot;&gt;
        &lt;title&gt;通过ajax调用WebService服务&lt;/title&gt;
        &lt;script&gt;
            
            var xhr = new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);
            function sendMsg(){
                var name = document.getElementById('name').value;
                //服务的地址
                var wsUrl = 'http://192.168.1.100:6789/hello';
                
                //请求体
                var soap = '&lt;soapenv:Envelope xmlns:soapenv=&quot;http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:q0=&quot;http://ws.itcast.cn/&quot; xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;' + 
                                     ' &lt;soapenv:Body&gt; &lt;q0:sayHello&gt;&lt;arg0&gt;'+name+'&lt;/arg0&gt;  &lt;/q0:sayHello&gt; &lt;/soapenv:Body&gt; &lt;/soapenv:Envelope&gt;';
                                     
                //打开连接
                xhr.open('POST',wsUrl,true);
                
                //重新设置请求头
                xhr.setRequestHeader(&quot;Content-Type&quot;,&quot;text/xml;charset=UTF-8&quot;);
                
                //设置回调函数
                xhr.onreadystatechange = _back;
                
                //发送请求
                xhr.send(soap);
            }
            
            function _back(){
                if(xhr.readyState == 4){
                    if(xhr.status == 200){
                            //alert('调用Webservice成功了');
                            var ret = xhr.responseXML;
                            var msg = ret.getElementsByTagName('return')[0];
                            document.getElementById('showInfo').innerHTML = msg.text;
                            //alert(msg.text);
                        }
                }
            }
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
            &lt;input type=&quot;button&quot; value=&quot;发送SOAP请求&quot; onclick=&quot;sendMsg();&quot;&gt;
            &lt;input type=&quot;text&quot; id=&quot;name&quot;&gt;
            &lt;div id=&quot;showInfo&quot;&gt;
            &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;

</code></pre>
<h2 id="url-connection-方式">url connection 方式</h2>
<p>听说主要用于android开发&hellip;.</p>
<pre><code class="language-java">public class App {

    public static void main(String[] args) throws Exception {
        //服务的地址
        URL wsUrl = new URL(&quot;http://192.168.1.100:6789/hello&quot;);
        
        HttpURLConnection conn = (HttpURLConnection) wsUrl.openConnection();
        
        conn.setDoInput(true);
        conn.setDoOutput(true);
        conn.setRequestMethod(&quot;POST&quot;);
        conn.setRequestProperty(&quot;Content-Type&quot;, &quot;text/xml;charset=UTF-8&quot;);
        
        OutputStream os = conn.getOutputStream();
        
        //请求体
        String soap = &quot;&lt;soapenv:Envelope xmlns:soapenv=\&quot;http://schemas.xmlsoap.org/soap/envelope/\&quot; xmlns:q0=\&quot;http://ws.itcast.cn/\&quot; xmlns:xsd=\&quot;http://www.w3.org/2001/XMLSchema\&quot; xmlns:xsi=\&quot;http://www.w3.org/2001/XMLSchema-instance\&quot;&gt;&quot; + 
                      &quot;&lt;soapenv:Body&gt; &lt;q0:sayHello&gt;&lt;arg0&gt;aaa&lt;/arg0&gt;  &lt;/q0:sayHello&gt; &lt;/soapenv:Body&gt; &lt;/soapenv:Envelope&gt;&quot;;
        
        os.write(soap.getBytes());
        
        InputStream is = conn.getInputStream();
        
        byte[] b = new byte[1024];
        int len = 0;
        String s = &quot;&quot;;
        while((len = is.read(b)) != -1){
            String ss = new String(b,0,len,&quot;UTF-8&quot;);
            s += ss;
        }
        System.out.println(s);
        
        is.close();
        os.close();
        conn.disconnect();
    }
}
</code></pre>
<h2 id="axis2">Axis2</h2>
<h3 id="wsdl2java-生成客户端-语法">wsdl2java-生成客户端-语法</h3>
<pre><code>    wsdl2java 语法：

wsdl2java 用于根据WSDL生成相应的服务端和客户端代码的生成工具。
命令行格式为：WSDL2Java [options] -uri &lt;url or path&gt; : A url or path to a WSDL
例如：
wsdl2java -uri http://localhost:8080/cxfService_0617/services/Hellows?wsdl -s -o build\client
 
其中常用的options具体如下：
-o &lt;path&gt; : 指定生成代码的输出路径
-a : 生成异步模式的代码
-s : 生成同步模式的代码
-p &lt;pkg&gt; : 指定代码的package名称
-l &lt;languange&gt; : 使用的语言(Java/C) 默认是java
-t : 为代码生成测试用例
-ss : 生成服务端代码 默认不生成
-sd : 生成服务描述文件 services.xml,仅与-ss一同使用
-d &lt;databinding&gt; : 指定databingding，例如，adb,xmlbean,jibx,jaxme and jaxbri
-g : 生成服务端和客户端的代码
-pn &lt;port_name&gt; : 当WSDL中有多个port时，指定其中一个port
-sn &lt;serv_name&gt; : 选择WSDL中的一个service
-u : 展开data-binding的类
-r &lt;path&gt; : 为代码生成指定一个repository
-ssi : 为服务端实现代码生成接口类
-S : 为生成的源码指定存储路径
-R : 为生成的resources指定存储路径
–noBuildXML : 输出中不生成build.xml文件
–noWSDL : 在resources目录中不生成WSDL文件
–noMessageReceiver : 不生成MessageReceiver类
</code></pre>
<h3 id="客户端调用">客户端调用</h3>
<pre><code class="language-java">public class App 
{
    public static void main( String[] args )
    {
        try {
            StockQuoteStub.GetQuote quote = new StockQuoteStub.GetQuote();
            quote.setSymbol(&quot;string&quot;);

            StockQuoteStub stub = new StockQuoteStub();
            StockQuoteStub.GetQuoteResponse response = stub.getQuote(quote);
            String result = response.getGetQuoteResult();

            System.out.println(result);
        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}
</code></pre>
<p>项目实战：</p>
<pre><code class="language-java">    public  String getYinHaiYZM(String nameURI, String userName,
            String passWord, String jyyzm, String jylsh1, String jybh) {
        try {
            YinHaiBusinessStub stub = new YinHaiBusinessStub();
            ServiceClient serviceClient = stub._getServiceClient();

            serviceClient.addHeader(AddSoapHeaderTecsun.getSOAPHeaderBlock(
                    nameURI, userName, passWord, jyyzm, jylsh1, jybh));
            YinHaiBusinessStub.GetJylsh jylsh = new YinHaiBusinessStub.GetJylsh();
            jylsh.setInputxml(AddSoapHeaderTecsun.getInputxml()
                    + &quot;&lt;input&gt;&lt;/input&gt;&quot;);
            YinHaiBusinessStub.GetJylshE jylshe = new YinHaiBusinessStub.GetJylshE();
            jylshe.setGetJylsh(jylsh);
            YinHaiBusinessStub.GetJylshResponse response = stub
                    .getJylsh(jylshe).getGetJylshResponse();
            String return_value = response.get_return();
            return return_value;
        } catch (AxisFault e) {
            e.printStackTrace();
        } catch (RemoteException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static SOAPHeaderBlock getSOAPHeaderBlock(String nameURI,
            String userName, String passWord, String jyyzm, String jylsh,
            String jybh) {
        // 获取创建工厂�?
        OMFactory oMFactory = OMAbstractFactory.getOMFactory();
        SOAPFactory sOAPFactory = OMAbstractFactory.getSOAP11Factory();
        // 利用工厂，创建命名空间和消息头�??
        OMNamespace oMNamespace = oMFactory.createOMNamespace(nameURI, &quot;in&quot;);
        SOAPHeaderBlock soapHeader = sOAPFactory.createSOAPHeaderBlock(
                &quot;system&quot;, oMNamespace);
        SOAPHeaderBlock name = sOAPFactory.createSOAPHeaderBlock(&quot;userName&quot;,
                null);
        name.addChild(sOAPFactory.createOMText(userName));
        SOAPHeaderBlock pass = sOAPFactory.createSOAPHeaderBlock(&quot;passWord&quot;,
                null);
        pass.addChild(sOAPFactory.createOMText(passWord));
        SOAPHeaderBlock lsh = sOAPFactory.createSOAPHeaderBlock(&quot;jylsh&quot;, null);
        lsh.addChild(sOAPFactory.createOMText(jylsh));

        SOAPHeaderBlock yzm = sOAPFactory.createSOAPHeaderBlock(&quot;jyyzm&quot;, null);
        yzm.addChild(sOAPFactory.createOMText(jyyzm));
        SOAPHeaderBlock bh = sOAPFactory.createSOAPHeaderBlock(&quot;jybh&quot;, null);
        bh.addChild(sOAPFactory.createOMText(jybh));
        soapHeader.addChild(name);
        soapHeader.addChild(pass);
        soapHeader.addChild(yzm);
        soapHeader.addChild(lsh);
        soapHeader.addChild(bh);
        return soapHeader;
    }
</code></pre>
<p>客户端调用总结：</p>
<ol>
<li>wsdl2java 生成客户端</li>
<li>实例化 stub类，并调用其中的方法（stub类封装了大量的类和方法，如返回值等也封装成了一个类，调用此类中的方法即可以得到返回值）</li>
</ol>
<h2 id="cxf">CXF</h2>
<pre><code class="language-sh">    wsdl2java 语法：

    wsdl2java -p com.tecsun.ws -d e:\temp\src -all xx.wsdl
</code></pre>
<p>参考：<a href="http://cxf.apache.org/docs/wsdl-to-java.html">CXF - WSDL to Java</a>，<a href="http://www.cnblogs.com/ChrisMurphy/p/5224160.html">wsdl2java &amp; wsimport 区别</a></p>
<h3 id="wsdl文件解释">WSDL文件解释</h3>
<p>xml-ws-wsdl文件详细解释:</p>
<p><img src="https://oscimg.oschina.net/oscnet/d8b5645745fcfbff090ca9698e5ee00b49d.jpg" alt="wsdl文件详细解释" title="wsdl文件详细解释"></p>
<p>xml-ws-wsdl文件详细解释2:</p>
<p><img src="https://oscimg.oschina.net/oscnet/f0ca534a6bab6ad2f5f210785046e411ec0.jpg" alt="wsdl文件详细解释2" title="wsdl文件详细解释2"></p>
<p>xml-ws-wsdl-cxf-调用详解:</p>
<p><img src="https://oscimg.oschina.net/oscnet/71ebefa8cc6ae62a710c1fc8e5c821766db.jpg" alt="cxf-调用详解" title="cxf-调用详解"></p>
<h3 id="客户端代码">客户端代码</h3>
<ul>
<li>依赖：</li>
</ul>
<pre><code class="language-xml">        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
            &lt;artifactId&gt;cxf-rt-frontend-jaxws&lt;/artifactId&gt;
            &lt;version&gt;${cxf.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
            &lt;artifactId&gt;cxf-rt-transports-http&lt;/artifactId&gt;
            &lt;version&gt;${cxf.version}&lt;/version&gt;
        &lt;/dependency&gt;
</code></pre>
<ul>
<li>JaxWsDynamicClientFactory使用：</li>
</ul>
<pre><code class="language-java">public Result commonWithPage(String jybh,String aac002,String aac003,String yac005,
    String isfrom, int pageNo, int pageSize,Class clazz) throws Exception{
        JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
        Client c = factory.createClient(YINHAI_URL);
        HTTPConduit http =(HTTPConduit) c.getConduit();
        HTTPClientPolicy hcp = new HTTPClientPolicy();
        hcp.setConnectionTimeout(200000);
        hcp.setReceiveTimeout(200000);
        http.setClient(hcp);
        c.getOutInterceptors().add(new AddSoapHeader2(Constants.YINHAI_NAMESPACE, USER, PASSWORD, &quot;&quot;, &quot;&quot;, jybh));
        String inputXml = &quot;&lt;input&gt;&lt;aac002&gt;&quot; + aac002 + &quot;&lt;/aac002&gt;&lt;aac003&gt;&quot; + aac003 + &quot;&lt;/aac003&gt;&quot; +
                &quot;&lt;yac005&gt;&quot; + yac005 + &quot;&lt;/yac005&gt;&lt;isfrom&gt;&quot; + converToNum(isfrom) + &quot;&lt;/isfrom&gt;&quot;  +
                &quot;&lt;startrow&gt;&quot; + (pageNo &gt; 1 ? ((pageNo-1)*pageSize)+1 : 1) + &quot;&lt;/startrow&gt;&quot; +
                &quot;&lt;endrow&gt;&quot; + (pageNo*pageSize) + &quot;&lt;/endrow&gt;&lt;/input&gt;&quot;;
        System.out.println(&quot;imputXml:&quot;+inputXml);
        Object[] obj = c.invoke(&quot;callBusiness&quot;,inputXml);
        String outputXML = &quot;&quot;;
        if(obj != null){
            outputXML = (String)obj[0];
        }
        
        System.out.println(&quot;==commonWithPage()中的outputXML====== start :&quot;);
        System.out.println(outputXML);
        System.out.println(&quot;===commonWithPage()中的outputXMLL end====&quot;);
        
        return XMLUtils.parseXml2Result(outputXML, clazz);
    }
</code></pre>
<p>注：YinHaiURL=http://10.131.134.1:7011/jypt/services/yinHaiBusiness?wsdl</p>
<p>设置SOAP请求头：</p>
<pre><code class="language-java">package com.tecsun.sisp.iface.outerface.egsec.session;

import java.util.List;
import javax.xml.namespace.QName;
import org.apache.cxf.binding.soap.SoapHeader;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.interceptor.Fault;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * Created by Administrator on 2016/3/23.
 */
public class AddSoapHeader2 extends AbstractSoapInterceptor {
    private String nameURI;
    private String userName;
    private String passWord;
    private String jyyzm;
    private String jylsh;
    private String jybh;
    private String fwlsh;
    private String nbffyzm;
    private String fwdysxh;

    public AddSoapHeader2() {
        super(&quot;write&quot;);
    }

    /**
     * 添加头信息
     * @param nameURI   URL
     * @param userName  用户名
     * @param passWord  密码
     * @param jyyzm     交易验证码
     * @param jylsh     流水号
     * @param jybh      交易编号
     */
    public AddSoapHeader2(String nameURI, String userName, String passWord, String jyyzm, String jylsh, String jybh) {
        super(&quot;write&quot;);
        this.nameURI = nameURI;
        this.userName = userName;
        this.passWord = passWord;
        this.jyyzm = jyyzm;
        this.jylsh = jylsh;
        this.jybh = jybh;
    }

    public void handleMessage(SoapMessage message)
            throws Fault {
        QName qname = new QName(&quot;RequestSOAPHeader&quot;);
        Document doc = DOMUtils.createDocument();

        Element el_username = doc.createElement(&quot;userName&quot;);
        el_username.setTextContent(this.userName);

        Element el_password = doc.createElement(&quot;passWord&quot;);
        el_password.setTextContent(this.passWord);

        Element el_jylsh = doc.createElement(&quot;jylsh&quot;);
        el_jylsh.setTextContent(this.jylsh);

        Element el_jyyzm = doc.createElement(&quot;jyyzm&quot;);
        el_jyyzm.setTextContent(this.jyyzm);

        Element el_jybh = doc.createElement(&quot;jybh&quot;);
        el_jybh.setTextContent(this.jybh);

        Element el_fwlsh = doc.createElement(&quot;fwlsh&quot;);
        el_fwlsh.setTextContent(this.fwlsh);

        Element el_nbffyzm = doc.createElement(&quot;nbffyzm&quot;);
        el_nbffyzm.setTextContent(this.nbffyzm);

        Element el_fwdysxh = doc.createElement(&quot;fwdysxh&quot;);
        el_fwdysxh.setTextContent(this.fwdysxh);

        Element root = doc.createElementNS(this.nameURI, &quot;in:system&quot;);
        root.appendChild(el_username);
        root.appendChild(el_password);
        root.appendChild(el_jylsh);
        root.appendChild(el_jyyzm);
        root.appendChild(el_jybh);
        root.appendChild(el_fwlsh);
        root.appendChild(el_nbffyzm);
        root.appendChild(el_fwdysxh);

        SoapHeader head = new SoapHeader(qname, root);
        List headers = message.getHeaders();
        headers.add(head);
        System.out.println(&quot;&gt;&gt;&gt;&gt;&gt;添加header&lt;&lt;&lt;&lt;&lt;&lt;&lt;&quot;);
    }
}

</code></pre>
<ul>
<li>本地客户端的使用</li>
</ul>
<pre><code class="language-java">    public static void main(String[] args) {
        StockQuote stockQuote = new StockQuote();

        StockQuoteSoap stockQuoteSoap = stockQuote.getStockQuoteSoap();
        String result = stockQuoteSoap.getQuote(&quot;string&quot;);
        System.out.println(result);

    }
</code></pre>

    </div>
    <div class="article-footer">
<blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    <li class="post-copyright-link hidden-xs">
      <strong>Permalink: </strong>
      <a href="https://rulerLwx.gitee.io/2019/08/java-xml-webservice/" title="Java-xml-WebService" target="_blank" rel="external">https://rulerLwx.gitee.io/2019/08/java-xml-webservice/</a>
    </li>
    <li class="post-copyright-license">
      <strong>License：</strong><a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN</a>
    </li>
  </ul>
</blockquote>

<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://gitee.com/rulerLwx" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="https://rulerLwx.gitee.io/avatar.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://gitee.com/rulerLwx" target="_blank"><span class="text-dark">rulerLwx</span><small class="ml-1x">thinking...</small></a></h3>
        <div>Good Good Study, Day Day Up~</div>
      </div>
    </figure>
  </div>
</div>
    </div>
  </article>
<section id="comments">
    <div id="vcomments"></div>
</section>

</div><nav class="bar bar-footer clearfix" data-stick-bottom>
    <div class="bar-inner">
        <ul class="pager pull-left">
            <li class="prev">
                <a href="https://rulerLwx.gitee.io/2019/08/java-tool-maven-1/" title="Java-tool-Maven-1"><i
                        class="icon icon-angle-left"
                        aria-hidden="true"></i><span>&nbsp;&nbsp;Older</span></a>
            </li>
            <li class="next">
                <a href="https://rulerLwx.gitee.io/2019/08/java-framework-mybatis-1/"
                    title="Java-framework-MyBatis-1"><span>Newer&nbsp;&nbsp;</span><i
                        class="icon icon-angle-right" aria-hidden="true"></i></a>
            </li>
            
            <li class="toggle-toc">
                <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false"
                    title="Catalogue" role="button">
                    <span>[&nbsp;</span><span>Catalogue</span>
                    <i class="text-collapsed icon icon-anchor"></i>
                    <i class="text-in icon icon-close"></i>
                    <span>]</span>
                </a>
            </li>
        </ul>
        <div class="bar-right">
            <div class="share-component" data-sites="weibo,qq,wechat"
                data-mobile-sites="weibo,qq,qzone"></div>
        </div>
    </div>
</nav>

</main><footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
<ul class="social-links">
    <li><a href="https://gitee.com/rulerLwx" target="_blank" title="gitee" data-toggle=tooltip data-placement=top >
            <i class="icon icon-gitee"></i></a></li>
    <li><a href="https://github.com/wolf-lea" target="_blank" title="github" data-toggle=tooltip data-placement=top >
            <i class="icon icon-github"></i></a></li>
</ul>
  <div class="copyright">
    &copy;2017  -
    2020
    <div class="publishby">
        Theme by <a href="https://github.com/xiaoheiAh" target="_blank"> xiaoheiAh </a>base on<a href="https://github.com/xiaoheiAh/hugo-theme-pure" target="_blank"> pure</a>.
    </div>
  </div>
</footer>

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_SVG"></script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
            showMathMenu: false, //disables context menu
            tex2jax: {
            inlineMath: [ ['$','$'], ['\\(','\\)'] ]
           }
    });
</script>


<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
<script>
    window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/highlight.min.js"></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/python.min.js" defer></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/javascript.min.js" defer></script><script>
    hljs.configure({
        tabReplace: '    ', 
        classPrefix: ''     
        
    })
    hljs.initHighlightingOnLoad();
</script>
<script src="https://rulerLwx.gitee.io/js/application.min.bdeb64b910570b6c41badc6a05b7afb0c8ad9efd8525de3c7257d59e786326a3.js"></script>
<script src="https://rulerLwx.gitee.io/js/plugin.min.51ff8c7317566f82259170fa36e09c4493adc9b9378b427a01ad3f017ebac7dd.js"></script>

<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: 'Posts',
                PAGES: 'Pages',
                CATEGORIES: 'Categories',
                TAGS: 'Tags',
                UNTITLED: '(Untitled)',
            },
            ROOT_URL: 'https:\/\/rulerLwx.gitee.io',
            CONTENT_URL: 'https:\/\/rulerLwx.gitee.io\/searchindex.json ',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script type="text/javascript" src="https://rulerLwx.gitee.io/js/insight.min.a343cd9a5a7698336b28ef3a7c16a3a1b1d2d5fb17dc8ed04022bbe08cc5459073a15bdafa3a8a58cdd56080784bdd69fa70b1ae8597565c799c57ed00f0e120.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script>
<script>
    tocbot.init({
        
        tocSelector: '.js-toc',
        
        contentSelector: '.js-toc-content',
        
        headingSelector: 'h1, h2, h3',
        
        hasInnerContainers: true,
    });
</script>

<script src="https://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine"></script>
<script type="text/javascript">
    var GUEST = ['nick', 'mail', 'link'];
    var meta = 'nick,mail';
    meta = meta.split(',').filter(function (item) {
        return GUEST.indexOf(item) > -1;
    });
    new Valine({
        el: '#vcomments',
        verify: null ,
        notify: null ,
        appId: 'IyAB0PSPRazTPDxitO1ddQ7O-gzGzoHsz',
        appKey: '5rBJTq4KidYF33eXwvRVhtEH',
        placeholder: 'enjoy~',
        avatar: 'mm',
        meta: meta,
        pageSize: '10' || 10,
        visitor: false 
});
</script>

  </body>
</html>
